<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item label="编号:" prop="brand.value">
                            <el-input v-model="queryParams.brand.value" placeholder="请输入编号" clearable />
                        </el-form-item>
                    </el-col> -->

                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col> -->
                </el-row>
            </el-form>

            
            <el-row :gutter="10" class="mb8">
                <!-- <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">采购申请</el-button>
                </el-col> -->
                <!-- <el-col :span="1.5">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col> -->
                <!-- <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col> -->
                <!-- <el-col :span="1.5">
                    <el-upload
                            class="upload-demo"
                            :action="api.uplode"
                            :on-preview="handlePreview"
                            :on-remove="handleRemove"
                            :before-remove="beforeRemove"
                            multiple
                            :limit="1"
                            :on-exceed="handleExceed"
                            :file-list="fileList">
                            <el-button size="small" type="primary">点击上传</el-button>
                            <div slot="tip" class="el-upload__tip">只能上传xlsx文件，且不超过500kb</div>
                    </el-upload>
                </el-col> -->
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <!-- <template v-slot:action> -->
                    <!-- <el-table-column label="操作" width="240" align="left"> -->
                        <!-- <template slot-scope="scope"> -->
                            <!-- <el-button class="btn-mar" size="mini" type="primary" icon="el-icon-edit">
                                <router-link
                                        :to="{
                                            path: 'output_index/output_info',
                                            query: {
                                                id: scope.row.id,
                                            }
                                        }"
                                    >
                                        查看明细
                                    </router-link>
                            </el-button> -->
                            <!-- <el-button class="btn-mar" size="mini" type="primary" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="api.edit">编辑</el-button> -->
                            <!-- <el-button class="btn-mar" size="mini" type="info" icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button> -->
                            <!-- <el-button class="btn-mar" size="mini" type="danger" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button> -->

                        <!-- </template> -->
                    <!-- </el-table-column> -->
                <!-- </template> -->
            </qa-table>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
        <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen"  :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData"  :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>

    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormDetailCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    
    data() {
        return {
            fileList: [],

            // table结构
            columns: [],
            get_id: 1,
            // 接口地址
            api: {
                index: `/admin/output/add_purchase_apply_list`,
                find: `/admin/output/find`,
                add: `/admin/output/add_purchase_apply`,
                edit: `/admin/output/edit_output_detail`,
                delete: `/admin/output/delete`,
                export: `/admin/output/export_detail`,
                uplode: `/admin/index/output_uplode`,
                status: `/admin/output/status`
            },
            editFormParams: {
            },
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
              //是否展示搜索
            showSearch: true,
            // 查询参数
            queryParams: {
                id: { value:undefined, op: '%like%'},

            },
        }
    },
    created () {
        this.initIndex()
    },
    watch: {
        
    },
    methods: {
        // 案列：当前组件格式化方法
        testFormatter(prop) {
            return prop
        },
        initIndex() {
            this.loading = true
            if(this.$route.query.id == '' || this.$route.query.id == undefined){
                this.get_id = 1
            }else{
                this.get_id = this.$route.query.id;
            }
            
            this.request
                .post(this.api.index, { 
                    ...this.pageInfo,
                    product_id:this.get_id,
                    ...this.formatQueryParams(this.queryParams),
                })
                .then(response => {
                    for(let i =0;i<response.table_header.length;i++){
                        if(response.table_header[i].label == 'status'){
                            response.table_header[i].label =  '审核状态'
                        }else if(response.table_header[i].label == 'color'){
                            response.table_header[i].label =  '颜色'
                        }else if(response.table_header[i].label == 'admin_id'){
                            response.table_header[i].label =  '申请人'
                        }
                    }
                    
                    this.tableData = response.data
                    this.total = response.count
                    this.columns = response.table_header
                })
                .finally(() => {
                    this.loading = false
                })
        },

        handleRemove(file, fileList) {
            console.log(file, fileList);
        },
        handlePreview(file) {
            console.log(file);
        },
        handleExceed(files, fileList) {
        this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
        },
        beforeRemove(file, fileList) {
        return this.$confirm(`确定移除 ${ file.name }？`);
        }

    }
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
</style>
